<template>
  <div class="movie-card" @click="handleClick">
    <div class="poster-container">
      <img :src="posterUrl" :alt="title" class="poster" />
      <div class="rating">{{ rating }}</div>
    </div>
    <div class="info">
      <h3 class="title">{{ title }}</h3>
      <p class="genre">{{ genre }}</p>
      <p class="description">{{ description }}</p>
    </div>
  </div>
</template>

<script setup lang="ts">
import { defineProps, defineEmits } from 'vue';

const props = defineProps({
  id: {
    type: Number,
    required: true
  },
  title: {
    type: String,
    required: true
  },
  posterUrl: {
    type: String,
    required: false,
    default: 'https://via.placeholder.com/300x450?text=No+Image'
  },
  rating: {
    type: String,
    required: false,
    validator: (value: number) => value >= 0 && value <= 10
  },
  genre: {
    type: String,
    required: false
  },
  description: {
    type: String,
    required: false
  }
});

const emit = defineEmits<{
  (e: 'click', id: number): void
}>();

const handleClick = () => {
emit('click', props.id);
};
</script>

<style scoped>
.movie-card {
  width: 100%;
  max-width: 150px;
  background-color: white;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  cursor: pointer;
}

.movie-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 24px rgba(22, 93, 255, 0.15);
}

.poster-container {
  position: relative;
  width: 100%;
  padding-top: 150%; /* 2:3 aspect ratio */
}

.poster {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.rating {
  position: absolute;
  top: 12px;
  right: 12px;
  background-color: #165DFF;
  color: white;
  font-weight: bold;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.9rem;
}

.info {
  padding: 16px;
}

.title {
  font-size: 0.9rem;
  font-weight: 600;
  margin: 0 0 8px 0;
  color: #333;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.genre {
  font-size: 0.65rem;
  color: #666;
  margin: 0 0 8px 0;
}

.description {
  font-size: 0.65rem;
  color: #444;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
</style>